import { request } from '@/utils/request'
import type { Quote, QuoteSearch, QuoteCreateRequest } from '@/types/quote'
import type { PageQuery } from '@/types/api'

// 获取报价单列表
export function getQuoteList(params?: QuoteSearch) {
  return request<Quote[]>({
    url: '/quote/list',
    method: 'get',
    params
  })
}

// 分页获取报价单列表
export function getQuotePage(params: PageQuery & QuoteSearch) {
  return request<{
    rows: Quote[]
    total: number
    pages?: number
    current?: number
    size?: number
  }>({
    url: '/quote/page',
    method: 'get',
    params
  })
}

// 获取报价单详情
export function getQuoteDetail(quoteId: number) {
  return request<Quote>({
    url: `/quote/${quoteId}`,
    method: 'get'
  })
}

// 新增报价单
export function addQuote(data: QuoteCreateRequest) {
  return request({
    url: '/quote',
    method: 'post',
    data
  })
}

// 修改报价单
export function updateQuote(data: QuoteCreateRequest) {
  return request({
    url: '/quote',
    method: 'put',
    data
  })
}

// 删除报价单
export function deleteQuote(quoteId: number) {
  return request({
    url: `/quote/${quoteId}`,
    method: 'delete'
  })
}

// 根据客户ID获取报价单列表
export function getQuotesByCustomerId(customerId: number) {
  return request<Quote[]>({
    url: `/quote/customer/${customerId}`,
    method: 'get'
  })
}

// 提交报价单
export function submitQuote(quoteId: number) {
  return request({
    url: `/quote/submit/${quoteId}`,
    method: 'put'
  })
}

// 接收报价单
export function receiveQuote(quoteId: number) {
  return request({
    url: `/quote/receive/${quoteId}`,
    method: 'put'
  })
}

// 拒绝报价单
export function rejectQuote(quoteId: number) {
  return request({
    url: `/quote/reject/${quoteId}`,
    method: 'put'
  })
}